package asteroids.model.expressions;

import asteroids.model.types.*;
import java.util.*;

/**
 * A subclass of expression (E) that represents the comparisons of doubles
 * 
 * @version 1.0
 * 
 * @author	Thijs Peirelinck & Wouter Parys
 *
 */
public abstract class DoubleComparison extends Comparison{

	public DoubleComparison(E e1, E e2) {
		super(e1, e2);
	}
	
	@Override
	public boolean isValidExpression() {
		return (getLeftOperand().getReturnType().equals("double") && getRightOperand().getReturnType().equals("double") && !(getLeftOperand() == this) && !(getRightOperand() == this));
	}
	
	@Override
	public boolean typeCheck(Map<String, T> globals) {
	boolean test1 = super.typeCheck(globals);
	boolean test2;
	//if both of the operands are equal test1 = true, one of the operands need to be of type "double" to make test2 = true
	if(getLeftOperand() instanceof Variable) {
		if(globals.get(getLeftOperand().getValue()) == null)
			return false;
		test2 = globals.get(getLeftOperand().getValue()).getReturnType().equals("double");
	}
	else 
		test2 = getLeftOperand().getReturnType().equals("double");
	return test1 && test2;
	}

}
